package com.niuke;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 7. 篮球比赛
 * https://blog.csdn.net/A_D_I_D_A_S/article/details/131488445
 */
public class NiukeMoni9 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] zhanLi = new int[10];
        int allZhanLi = 0;
        for (int i = 0; i < 10; i++) {
            zhanLi[i] = scanner.nextInt();
            allZhanLi += zhanLi[i];
        }

        // 排序之后最弱战力必须和最强战力在一个组才能均衡。
        Arrays.sort(zhanLi);
        int curr = zhanLi[0] + zhanLi[9];

        // 对剩下的三名篮球队友做全部可能得到偏差结果，并挑选出最小的结果作为最终结果
        int res = Integer.MAX_VALUE;
        for (int i = 1; i < 7; i++) {
            for (int j = i + 1; j < 8; j++) {
                for (int k = j + 1; k < 9; k++) {
                    int currRes =
                            Math.abs(allZhanLi - 2 * (curr + zhanLi[i] + zhanLi[j] + zhanLi[k]));
                    res = Math.min(res, currRes);
                }
            }
        }

        System.out.println(res);
    }

}
